home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / networking / misc / sana2.lha / sana2 / examples / configure / configure.c next >
Encoding:
C/C++ Source or Header  |  1991-11-18  |  3.7 KB  |  151 lines

  1. /*
  2. **  $Id: configure.c,v 1.2 91/11/12 16:23:41 dlarson Exp Locker: dlarson $
  3. **
  4. **  SANA-II driver configuration example.
  5. **
  6. **  Copyright 1991 Commodore-Amiga, Inc.
  7. **
  8. **  This code may be modified and used freely on Amiga computers.
  9. **
  10. **
  11. **  This example is pretty ugly and should be cleaned up.  Sorry.
  12. **  Still, you should be able to see the proper steps to take
  13. **  in configuring a SANA-II device.
  14. */
  15.  
  16. #define NOBUFFS
  17. #include "/skeleton/skeleton.h"
  18.  
  19. struct MsgPort   *DevPort = NULL;
  20. struct IOSana2Req *IOB1    = NULL;
  21.  
  22. int    DeviceOpen = 0;
  23. long    DevBits;
  24. int    NumBytes;
  25.  
  26. void DoConfig(UBYTE *Address);
  27. void DoGetAddr(void);
  28. void DoQuery(struct Sana2DeviceQuery *q);
  29. void DoPrintAddr(void);
  30.  
  31.  
  32. main(int argc, char *argv[])
  33. {
  34. int i;
  35. long temp;
  36. struct Sana2DeviceQuery Query;
  37.  
  38.         if(!initdev())
  39.         {
  40.             printf("Open Failed.\n");
  41.             goto bottom;
  42.         }
  43.         printf("About to Query the device.\n");
  44.     Query.SizeAvailable = sizeof(Query);
  45.     DoQuery(&Query);
  46.     if(IOB1->ios2_Req.io_Error)
  47.     {
  48.                 printf("ERROR RETURNED: %ld\n", (long)IOB1->ios2_Req.io_Error);
  49.         goto bottom;
  50.          }
  51.         if(Query.AddrFieldSize%8 != 0 || Query.AddrFieldSize == 0)
  52.     {
  53.         printf("Oh, no!  There really is funny hardware in the world!\n"
  54.                "Address field is %d bits.  This example needs to be\n"
  55.                "updated to understand address fields with a number of\n"
  56.                "bits not divisible by eight.\n", Query.AddrFieldSize);
  57.         goto bottom;
  58.     }
  59.     NumBytes = Query.AddrFieldSize/8;
  60.     if(argc>1)
  61.     {
  62.         for(i=0; i<NumBytes; i++)
  63.         {
  64.             sscanf(argv[1]+(i*3), "%lx", &temp);
  65.             IOB1->ios2_SrcAddr[i] = (char)temp;
  66.         }
  67.     }else
  68.     {
  69.         printf("\nNo user address, getting ROM address.\n");
  70.         DoGetAddr();
  71.         if (IOB1->ios2_Req.io_Error)
  72.         {
  73.             printf("ERROR RETURNED: 0x%lx\n",
  74.                            (long)IOB1->ios2_Req.io_Error);
  75.             goto bottom;
  76.              }
  77.          }
  78.          printf("SrcAddr is one we're going to attempt to configure with:\n");
  79.     DoPrintAddr();
  80.     printf("Attempting to set address\n");
  81.     DoConfig(IOB1->ios2_SrcAddr);
  82.     if(IOB1->ios2_Req.io_Error)
  83.     {
  84.         if(IOB1->ios2_Req.io_Error == S2ERR_BAD_STATE &&
  85.            IOB1->ios2_WireError == S2WERR_IS_CONFIGURED)
  86.             printf("Pardon Me. I'm Already Configured!\n");
  87.         else
  88.             printf("ERROR CODE:%ld  WERR:%ld\n",
  89.                 (long)IOB1->ios2_Req.io_Error,
  90.                 (long)IOB1->ios2_WireError);
  91.     } else
  92.     {
  93.         printf("Configured.  Results (SrcAddr is the address actually config'd to):\n");
  94.         DoPrintAddr();
  95.         printf("S2_GETSTATIONADDRESS and results (Src=Current  Dst=Default):\n");
  96.         DoGetAddr();  /* really should check for an error, device could be offline, for example  */
  97.         DoPrintAddr();
  98.     }
  99. bottom: closedev();
  100. }
  101.  
  102.  
  103. void DoConfig(UBYTE *Address)
  104. {
  105. register UBYTE *p = IOB1->ios2_SrcAddr;
  106. register i;
  107.  
  108.         IOB1->ios2_Req.io_Error   = 0;
  109.         IOB1->ios2_Req.io_Flags   = IOF_QUICK;
  110.         IOB1->ios2_Req.io_Command = S2_CONFIGINTERFACE;
  111.         for(i = 0; i <  NumBytes; i++)
  112.             *(p++) = *(Address++);
  113.         DoIO((struct IORequest *)IOB1);
  114. }
  115.  
  116.  
  117. void DoQuery(struct Sana2DeviceQuery *q)
  118. {
  119.  
  120.         IOB1->ios2_Req.io_Error   = 0;
  121.         IOB1->ios2_Req.io_Flags   = IOF_QUICK;
  122.         IOB1->ios2_Req.io_Command = S2_DEVICEQUERY;
  123.         IOB1->ios2_StatData = q;
  124.         DoIO((struct IORequest *)IOB1);
  125.         IOB1->ios2_StatData = NULL;
  126. }
  127.  
  128.  
  129. void DoGetAddr(void)
  130. {
  131.  
  132.         IOB1->ios2_Req.io_Error   = 0;
  133.         IOB1->ios2_Req.io_Flags   = IOF_QUICK;
  134.         IOB1->ios2_Req.io_Command = S2_GETSTATIONADDRESS;
  135.         DoIO((struct IORequest *)IOB1);
  136. }
  137.  
  138. void DoPrintAddr(void)
  139. {
  140. register i;
  141.  
  142.     printf("SrcAddr: ");
  143.         for (i = 0; i <  NumBytes; i++)
  144.         printf("%02x ", (long)(IOB1->ios2_SrcAddr[i] & 0xFF)) ;
  145.     printf("\nDstAddr: ");
  146.         for (i = 0; i <  NumBytes; i++)
  147.         printf("%02x ", (long)(IOB1->ios2_DstAddr[i] & 0xFF)) ;
  148.     printf("\n");
  149. }
  150.  
  151.